if(!dojo._hasResource["market.widgets.component.Comment"]){
dojo._hasResource["market.widgets.component.Comment"]=true;
require(["dojo/_base/declare","dijit/_Widget","dojo/query","dojo/dom","dojo/dom-construct","dojo/_base/array","dojo/html","dojo/fx"],function(declare,_widget,query,dom,contruct,array,html,fx){
declare("market.widgets.component.Comment",[_widget],{
_commentHtml:'<div class="c_c_b_c"><img class="c_c_a_c" src="getContent/{avatarGUID}/small"><div class="c_c_n"><span class="nickName">{name}</span> - {content}</div></div><div class="clear"></div>',
_inputcommentHtml:'<div class="c_b_b_c"><div class="c_b_b_c_f">'+globalAddCommment+'</div></div><div class="clear"></div>',
_currentPost:null,parentNode:null,commentNode:null,_divPost:null,newsGUID:null,divIcon:null,_currentIcon:null,viewParent:null,newsId:null,
show:function(){
   if (this._divPost != null){
      contruct.destroy(this._divPost);
      this._displayIconComment();
   }
   this._currentIcon=this.divIcon;
   this._hiddenIconComment();
   this._divPost=contruct.create('div',null,this.parentNode,'last');
   this._currentPost=SYSTEMWIDGET.contentEditor({targetNode:this._divPost,editId:'postComment',value:'',handelEvents:this._editorEvents(),hasEdit:true,ignoreEdit:true},true);
   this._currentPost.showEditor();
},
display:function(newGUID){
   var widget=this;
   var args = {ajaxUrl:'news/'+newGUID+'/comments',contentId:'center_content',callback:function(data){
      widget._parseComments(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
hidden:function(){
   var firstNode=query('div[name="contentComment"] > div:first-child',this.viewParent)[0];
   fx.wipeOut({node:firstNode,onEnd:function(){
      contruct.destroy(firstNode);
   }}).play();
   this._setIconStatus('down');
},
_editorEvents:function(){
   var widget=this;
   return {
      cancelClick:function(){
         contruct.destroy(widget._divPost);
         widget._displayIconComment();
      },
      saveClick:function(data){
         var contentComment=data;
         var objectToQuery={'content':data};
         var args={ajaxUrl:'news/'+widget.newsId+'/comment',postData:dojo.objectToQuery(objectToQuery),callback:function(){
            widget._showLatestComment(contentComment);
         }};
         SYSTEMWIDGET.ajaxWidget(args).callXhrPostJSON();
         contruct.destroy(widget._divPost);
      }
   };
},
_showLatestComment:function(content){
   var commentObj={content:content,name:getCurrentName(),avatarGUID:getContentGUID(participant.avatarGUID)};
   var commentHtml=dojo.replace(this._commentHtml,commentObj);
   var comments=query('> div.c_b_b_c_last',this.commentNode);
   if (comments.length>0){
      html.set(comments[0],commentHtml);
   }else{
      contruct.create('div',{'innerHTML':commentHtml,'class':'c_b_b_c_last'},this.commentNode,'first');
   }
   var aCom=query('div.c_c_c > a',this.commentNode.parentNode)[1];
   var hidden=query('input[type="hidden"]',aCom);
   var toltalNumbers=Number(hidden[2].value)+1;
   hidden[3].value='up';
   hidden[2].value=toltalNumbers;
   aCom.textContent='Comments ('+toltalNumbers+')';
   this._displayIconComment();
},
_parseComments:function(comments){
   var node=query('div[name="contentComment"]',this.viewParent)[0];
   var fxNode=contruct.create('div',{'style':'display:none'},node,'first');
   for (var index=1;index<comments.length;index++){
      var comment=comments[index];
      var partcp=comment.participant;
      var commentObj={content:comment.content,name:getPartViewName(partcp),avatarGUID:getPartGUID(partcp)};
      var commentHtml=dojo.replace(this._commentHtml,commentObj);
      contruct.create('div',{'innerHTML':commentHtml,'class':'c_b_b_c'},fxNode,'first');
   }
   fx.wipeIn({node:fxNode}).play();
   this._setIconStatus('up');
},
_setIconStatus:function(status){
   var aCom=query('div.c_c_c > a',this.viewParent)[1];
   var hidden=query('input[type="hidden"]',aCom);
   hidden[3].value=status;
},
_displayIconComment:function(){
   this._currentIcon.style.display='';
},
_hiddenIconComment:function(){
   this._currentIcon.style.display='none';
}
});});}
